package LogicaClasesNew;


import Logica.exceptions.NonexistentEntityException;
import Logica.exceptions.PreexistingEntityException;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Properties;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.ws.Endpoint;


@WebService
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public class WsIproveedor {
    
    private Endpoint endpoint = null;
    private IcontroladorProveedor ICP;

    //Constructor que publica el WebService con sus metodos.
    public WsIproveedor() {
        
    Fabrica fabrica = Fabrica.getInstance();
    this.ICP = fabrica.getControladorProveedor();
    try{
    Properties preferences = new Properties();
    FileInputStream in = new FileInputStream(System.getProperty("user.home")+"/configWebServices.ini");
    preferences.load(in);
    String host = preferences.getProperty("Host");
    String port = preferences.getProperty("Port");
    endpoint = Endpoint.publish("http://"+host+":"+port+"/iproveedor", this);
    }
    catch(Exception ex){
    //    endpoint = Endpoint.publish("http://localhost:8280/iproveedor", this);
    }
		
//.....WebMethod.....
    }
    
    @WebMethod
    public void createProveedor(String Compania, String Web, String Nickname, String Nombre, String Apellido, String FechNacim, String password, String Mail) throws PreexistingEntityException, Exception    {
    ICP.createProveedor(Mail, Mail, Nickname, Nombre, Apellido, FechNacim, password, Mail);
    }
    
    @WebMethod(exclude=true)
    public void createProveedor2(String Compania, String Web, String Nickname, String Nombre, String Apellido, String FechNacim, String password, String Mail, byte[] Foto) throws PreexistingEntityException, Exception{
        ICP.createProveedor2(Compania, Web, Nickname, Nombre, Apellido, FechNacim, password, Mail, Foto);
    }
    
    @WebMethod
    public Proveedor findProveedor(String Nickname){
        return ICP.findProveedor(Nickname);
    }
    
    @WebMethod
    public void addProductoProveedor(int numRefProd, String Nickname) throws NonexistentEntityException, Exception{
        ICP.addProductoProveedor(numRefProd, Nickname);
    }
    
    @WebMethod
    public ArrayList<Proveedor> findProveedorEntities(){
        return new ArrayList(ICP.findProveedorEntities());
    }
    
    
    @WebMethod
    public ArrayList<Producto> getListadoProductosXprove(String nickname){
        return new ArrayList(ICP.getListadoProductosXproveedor(nickname));
    }
    
    @WebMethod
    public void RemoveProductoProveedor(int numRefProd, String Nickname){
        ICP.RemoveProductoProveedor(numRefProd, Nickname);
    }  
   
    @WebMethod(exclude = true)
	public Endpoint getEndpoint() {
            return endpoint;
    }
    
}
